import request from '@/utils/request'
import {encrypt} from '@/utils/rsaEncrypt'


export function list(params) {
  return request({
    url: 'admin/user/list',
    method: 'get',
    params
  })
}


export function allList(params) {
  return request({
    url: 'admin/user/all',
    method: 'post',
    params
  })
}

export function add(data) {
  return request({
    url: 'admin/user/save',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'admin/user/del',
    method: 'post',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'admin/user/save',
    method: 'post',
    data
  })
}

export function editUser(data) {
  return request({
    url: 'admin/user/info/save',
    method: 'post',
    data
  })
}

export function enable(data) {
  return request({
    url: 'admin/user/enable',
    method: 'post',
    data
  })
}

export function resetPassword(data) {
  return request({
    url: `admin/user/resetPassword/${data.id}`,
    method: 'post'
  })
}

export function updatePass(form) {
  const data = {
    oldPass: form.oldPass ? encrypt(form.oldPass) : null,
    newPass: form.newPass ? encrypt(form.newPass) : null,
    email: form.email || ''
  }
  return request({
    url: 'admin/user/changePassword/' + form.id,
    method: 'post',
    data
  })
}

export default {add, edit, enable, del, allList, updatePass,list}

